package com.example.myapplication;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.LinearLayout;

import com.example.myapplication.fragment.HelpFragment;
import com.example.myapplication.fragment.HomeFragment;
import com.example.myapplication.fragment.MeFragment;
import com.example.myapplication.fragment.NewsFragment;
import com.example.myapplication.fragment.ServlerFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class MainActivity extends AppCompatActivity {
    private LinearLayout page;
    private BottomNavigationView botView;
    private HelpFragment helpFragment;
    private HomeFragment homeFragment;
    private ServlerFragment servlerFragment;
    private MeFragment meFragment;
    private NewsFragment newsFragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        page = findViewById(R.id.page);
        botView = findViewById(R.id.bot_view);

        helpFragment = new HelpFragment();
        homeFragment = new HomeFragment();
        newsFragment = new NewsFragment();
        meFragment = new MeFragment();
        servlerFragment = new ServlerFragment();

        getSupportFragmentManager().beginTransaction().replace(R.id.page,homeFragment).commit();
        botView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.home:
                        getSupportFragmentManager().beginTransaction().replace(R.id.page, homeFragment).commit();
                        break;
                    case R.id.help:
                        getSupportFragmentManager().beginTransaction().replace(R.id.page, helpFragment).commit();
                        break;
                    case R.id.servler:
                        getSupportFragmentManager().beginTransaction().replace(R.id.page, servlerFragment).commit();
                        break;
                    case R.id.news:
                        getSupportFragmentManager().beginTransaction().replace(R.id.page, newsFragment).commit();
                        break;
                    case R.id.me:
                        getSupportFragmentManager().beginTransaction().replace(R.id.page, meFragment).commit();
                        break;
                }
                return true;
            }
        });

    }
}